import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter1/pages/first_page.dart';

class CustomAnimatedBottomBar extends StatelessWidget {
  final selectedIndex;
  final double iconSize;
  final Color? backgroundColor;
  final bool showElevation;
  final Duration animationDuration;
  final List<MyBottomNavigationBarItem> items;
  final MainAxisAlignment mainAxisAlignment;
  final double itemCornerRadius;
  final double containerHeight;
  final Curve curve;
  final ValueChanged<int> onItemSelected;

  const CustomAnimatedBottomBar(
      {Key? key,
      this.selectedIndex,
      this.iconSize = 30,
      this.backgroundColor,
      this.showElevation = true,
      this.animationDuration = const Duration(milliseconds: 200),
      this.mainAxisAlignment = MainAxisAlignment.spaceEvenly,
      this.itemCornerRadius = 24,
      this.containerHeight = 48,
      this.curve = Curves.easeInOut,
      required this.items,
      required this.onItemSelected})
      : assert(items.length >= 2 && items.length <= 5),
        super(key: key);




  @override
  Widget build(BuildContext context) {
    final bgColor = backgroundColor ?? Theme.of(context).bottomAppBarColor;
    return SafeArea(
      child: Container(
        width: double.infinity,
        height: containerHeight,
        decoration: BoxDecoration(color: bgColor, boxShadow: [
          if (showElevation)
            const BoxShadow(
              color: Colors.black12,
              blurRadius: 2,
            )
        ]),
        child: SafeArea(
          child: Container(
            width: double.infinity,
            height: containerHeight,
            padding: EdgeInsets.symmetric(vertical: 10, horizontal: 8),
            child: Row(
              mainAxisAlignment: mainAxisAlignment,
              children: List.generate(items.length, (index) {
                return GestureDetector(
                    onTap: () {
                      onItemSelected(index);
                    },
                    child: GestureDetector(
                      onTap: () {
                        onItemSelected(index);
                      },
                      child: _ItemWidget(
                        curve: curve,
                        item: items[index],
                        isSelected: (index == selectedIndex),
                        iconSize: iconSize,
                        itemCornerRadius: itemCornerRadius,
                        animationDuration: animationDuration,
                        backgroundColor: bgColor,
                      ),
                    ));
              }),
            ),
          ),
        ),
      ),
    );
  }
}

class _ItemWidget extends StatelessWidget {
  final double iconSize;
  final bool isSelected;
  final MyBottomNavigationBarItem item;
  final Color backgroundColor;
  final double itemCornerRadius;
  final Duration animationDuration;
  final Curve curve;

  const _ItemWidget({
    Key? key,
    required this.iconSize,
    required this.isSelected,
    required this.item,
    required this.backgroundColor,
    required this.itemCornerRadius,
    required this.animationDuration,
    this.curve = Curves.easeInOut,
  }) : super(key: key);







  @override
  Widget build(BuildContext context) {
    return Semantics(
      container: true,
      selected: isSelected,
      child: AnimatedContainer(
        width: isSelected ? 100 : 50,
        duration: animationDuration,
        curve: curve,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(itemCornerRadius),
            color: isSelected
                ? item.activeColor.withOpacity(.2)
                : backgroundColor),
        child: SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          physics: NeverScrollableScrollPhysics(),
          child: Container(
            width: isSelected ? 100 : 50,
            padding: EdgeInsets.symmetric(horizontal: 8),
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                IconTheme(
                  data: IconThemeData(
                      size: iconSize,
                      color: isSelected
                          ? item.activeColor.withOpacity(1)
                          : (item.inactiveColor ?? item.activeColor)),
                  child: item.icon,
                ),
                isSelected
                    ? Expanded(
                        child: Container(
                        padding: EdgeInsets.symmetric(horizontal: 4),
                        child: DefaultTextStyle.merge(
                            child: item.title,
                            style: TextStyle(
                              color: item.activeColor,
                              fontWeight: FontWeight.bold,
                            ),
                            maxLines: 1,
                            textAlign: item.textAlign),
                      ))
                    : Text(''),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Function thisBook =(){

};
